import 'package:flutter/material.dart';
import 'package:webview_all/webview_all.dart';

import '../app_manager.dart';

class Webpage extends StatefulWidget {
  final WebViewModel data;
  bool isFavorite;

  Webpage(this.data, this.isFavorite,{super.key});

  @override
  State<Webpage> createState() => _WebpageState();
}

class _WebpageState extends State<Webpage> {

  @override
  void initState() {
    super.initState();
    debugPrint("data: ${widget.data.url}");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          actions: [
            IconButton(icon: Icon(widget.isFavorite == true ? Icons.favorite :Icons.favorite_border),color: AppManager.isLogin == true ? Colors.red : Colors.grey,onPressed: (){
              setState(() {
                if(AppManager.isLogin == true) {
                  widget.isFavorite = !widget.isFavorite;
                  //TODO 收藏按钮流程
                }else{
                  //TODO 进入登录页面
                }
              });
            })
          ],
          leading: InkWell(
            onTap: (){
              Navigator.pop(context);
            },
            child: Icon(Icons.arrow_back,color: Colors.white),
          ),
          title: Text(widget.data.title, style: TextStyle(color: Colors.white,fontSize: 15.0)),
          backgroundColor: Colors.blue,
        ),
        body: Center(child: Webview(url: widget.data.url)),
      ),
    );
  }
}



class WebViewModel {
  String title;
  String url;

  WebViewModel(this.title, this.url);
}
